<template>
    <view>
        <view class="topbar" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
            <text @tap="topbarFn" :class="'item ' + (currentTab == index ? 'active' : '')" :data-idx="index" v-for="(item, index) in topbar" :key="index">{{ item }}</text>
        </view>
        <block v-if="currentTab == 0">
            <view class="my_follow" v-if="LIST1.length > 0">
                <block v-for="(dl, idx_list) in LIST1" :key="idx_list">
                    <view class="dl" :data-uid="item.uid" v-if="item != null" v-for="(item, idx_dl) in dl" :key="idx_dl">
                        <view @tap="uidFn" class="dt" :data-uid="item.uid">
                            <image mode="aspectFill" :src="item.photo_s"></image>
                        </view>

                        <view class="dd">
                            <view class="h4">
                                <image class="ugrade1" :src="item.grade_ico"></image>
                                {{ item.nickname }}
                            </view>
                            <view class="h6">
                                <block v-for="(D, Didx) in item.data" :key="Didx">
                                    {{ D }}

                                    <text class="b" v-if="Didx + 1 != item.data.length">/</text>
                                </block>
                            </view>
                        </view>

                        <button
                            @tap="gzdelFn"
                            :class="item.btn.class + ' ico'"
                            :data-id="item.id"
                            :data-idx_dl="idx_dl"
                            :data-idx_list="idx_list"
                            :style="'--color:' + color"
                            type="button"
                        >
                            {{ item.btn.title }}
                        </button>
                    </view>
                </block>
            </view>
            <view class="nodata" v-if="nodatabox1">
                <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
                暂无信息
            </view>
        </block>
        <block v-if="currentTab == 1">
            <view class="my_follow" v-if="LIST2.length > 0">
                <block v-for="(dl, idx_list) in LIST2" :key="idx_list">
                    <view class="dl" :data-uid="item.uid" v-for="(item, idx_dl) in dl" :key="idx_dl">
                        <view @tap="uidFn" class="dt" :data-uid="item.uid">
                            <image mode="aspectFill" :src="item.photo_s"></image>
                        </view>

                        <view class="dd">
                            <view class="h4">
                                <image class="ugrade1" :src="item.grade_ico"></image>
                                {{ item.nickname }}
                            </view>
                            <view class="h6">
                                <block v-for="(D, Didx) in item.data" :key="Didx">
                                    {{ D }}

                                    <text class="b" v-if="Didx + 1 != item.data.length">/</text>
                                </block>
                            </view>
                        </view>

                        <button
                            @tap="gzdelFn2"
                            :class="item.btn.class + ' ico'"
                            :data-cls="item.btn.class"
                            :data-idx_dl="idx_dl"
                            :data-idx_list="idx_list"
                            :data-uid="item.uid"
                            :style="'--color:' + color"
                            type="button"
                        >
                            {{ item.btn.title }}
                        </button>
                    </view>
                </block>
            </view>
            <view class="nodata" v-if="nodatabox2">
                <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
                暂无信息
            </view>
        </block>
        <block v-if="currentTab == 2">
            <view class="my_follow" v-if="LIST3.length > 0">
                <block v-for="(dl, idx_list) in LIST3" :key="idx_list">
                    <view class="dl" :data-uid="item.uid" v-if="item != null" v-for="(item, idx_dl) in dl" :key="idx_dl">
                        <view @tap="uidFn" class="dt" :data-uid="item.uid">
                            <image mode="aspectFill" :src="item.photo_s"></image>
                        </view>

                        <view class="dd">
                            <view class="h4">
                                <image class="ugrade1" :src="item.grade_ico"></image>
                                {{ item.nickname }}
                            </view>
                            <view class="h6">
                                <block v-for="(D, Didx) in item.data" :key="Didx">
                                    {{ D }}

                                    <text class="b" v-if="Didx + 1 != item.data.length">/</text>
                                </block>
                            </view>
                        </view>

                        <button
                            @tap="hmdFn"
                            :class="item.btn.class + ' ico'"
                            :data-cls="item.btn.class"
                            :data-idx_dl="idx_dl"
                            :data-idx_list="idx_list"
                            :data-uid="item.uid"
                            :style="'--color:' + color"
                            type="button"
                        >
                            {{ item.btn.title }}
                        </button>
                    </view>
                </block>
            </view>
            <view class="nodata" v-if="nodatabox2">
                <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
                暂无信息
            </view>
        </block>
        <view class="loading" v-if="loading_flag">
            <image class="loading_ico" src="/static/res/img/loading_ico.svg" v-if="loading_ico_flag"></image>
            <text>{{ loading_str }}</text>
        </view>
        <view class="blank"></view>
    </view>
</template>

<script>
var a = require('../../@babel/runtime/helpers/defineProperty');
var t = require('../../res/www.a9a.cn.js');
var app = getApp();
var n = 2;
var o = true;
var s = uni.getStorageSync('COOK_U');
export default {
    data() {
        return {
            topbar: ['我喜欢', '喜欢我', '黑名单'],
            currentTab: 0,
            loading_flag: false,
            loading_ico_flag: false,
            loading_str: '拼命加载中',
            color: '',
            rgbcolor: '',
            LIST1: [],
            idx_list: [],
            dl: [],
            idx_dl: 0,
            Didx: 0,
            nodatabox1: '',
            LIST2: [],
            nodatabox2: '',
            LIST3: []
        };
    },
    onLoad: function (a) {
        var that = this;
        app.globalData.get_config('_ZEAI').then(function (e) {
            that.setData({
                color: e.color,
                rgbcolor: t.c16_rgb(e.color)
            });
            n = 2;
            o = true;
            that.get_data(a.t);
        });
    },
    onReachBottom: function () {
        var that = this;
        var s = parseInt(this.currentTab) + 1;
        switch (s) {
            case 1:
                var i = this.LIST1;
                break;
            case 2:
                i = this.LIST2;
                break;
            case 3:
                i = this.LIST3;
        }
        var r = uni.getStorageSync('COOK_U');
        if (o) {
            o = false;
            that.setData({
                loading_ico_flag: true
            });
            app.globalData.ajax({
                url: 'my_follow.php',
                data: {
                    submitok: 'list',
                    t: s,
                    p: n,
                    openid: r.openid
                },
                success: function (e) {
                    switch (s) {
                        case 1:
                            var r = e.LIST1;
                            break;
                        case 2:
                            r = e.LIST2;
                            break;
                        case 3:
                            r = e.LIST3;
                    }
                    if (r.length < 1) {
                        that.setData({
                            loading_flag: true,
                            loading_ico_flag: false,
                            loading_str: '已全部加载完成'
                        });
                        return void (o = false);
                    }
                    that.setData(a({}, 'LIST' + s + '[' + i.length + ']', r));
                    n += 1;
                    o = true;
                }
            });
        }
    },
    methods: {
        topbarFn: function (a) {
            var t = parseInt(a.currentTarget.dataset.idx);
            this.setData({
                currentTab: t
            });
            this.get_data(t + 1);
        },

        get_data: function (t) {
            var that = this;
            t = parseInt(t);
            app.globalData.chklogin().then(function (a) {
                a || uni.navigateBack();
            });
            o = false;
            s = uni.getStorageSync('COOK_U');
            app.globalData.ajax({
                url: 'my_follow.php',
                data: {
                    submitok: 'list',
                    t: t,
                    openid: s.openid
                },
                success: function (e) {
                    switch (t) {
                        case 1:
                            var s = e.LIST1;
                            break;
                        case 2:
                            s = e.LIST2;
                            break;
                        case 3:
                            s = e.LIST3;
                    }
                    if (1 == e.flag) {
                        var i;
                        if (s.length >= 15) {
                            that.setData({
                                loading_flag: true,
                                loading_ico_flag: true
                            });
                        }
                        if (0 == s.length) {
                            that.setData(
                                a(
                                    {
                                        loading_flag: false
                                    },
                                    'nodatabox' + t,
                                    true
                                )
                            );
                        } else {
                            that.setData((a((i = {}), 'LIST' + t + '[0]', s), a(i, 'nodatabox' + t, false), a(i, 'loading_flag', false), i));
                        }
                        o = true;
                    } else {
                        uni.showModal({
                            content: e.msg,
                            confirmColor: that.color,
                            confirmText: '朕知道了',
                            showCancel: false,
                            success: function (a) {
                                uni.navigateBack();
                            }
                        });
                    }
                }
            });
        },

        uidFn: function (a) {
            var t = a.currentTarget.dataset.uid;
            uni.navigateTo({
                url: '/pagesA/u/u?uid=' + t
            });
        },

        gzdelFn: function (t) {
            var that = this;
            uni.showModal({
                content: '取消关注后，你将无法接收Ta的动态哦',
                confirmColor: that.color,
                cancelText: '我再想想',
                confirmText: '取消关注',
                success: function (o) {
                    if (o.confirm) {
                        var i = t.currentTarget.dataset.id;
                        var r = t.currentTarget.dataset.idx_list;
                        var c = t.currentTarget.dataset.idx_dl;
                        app.globalData.ajax({
                            url: 'my_follow.php',
                            data: {
                                submitok: 'follow_del',
                                id: i,
                                openid: s.openid
                            },
                            success: function (t) {
                                if (1 == t.flag) {
                                    that.setData(a({}, 'LIST1[' + r + '][' + c + ']', null));
                                } else {
                                    uni.showToast({
                                        title: t.msg,
                                        icon: 'none',
                                        mask: true
                                    });
                                }
                            }
                        });
                    }
                }
            });
        },

        gzdelFn2: function (t) {
            var that = this;
            var o = t.currentTarget.dataset.uid;
            var i = t.currentTarget.dataset.idx_list;
            var r = t.currentTarget.dataset.idx_dl;
            if ('addgz' == t.currentTarget.dataset.cls) {
                app.globalData.ajax({
                    url: 'my_follow.php',
                    data: {
                        submitok: 'ajax_fans_gz',
                        uid: o,
                        openid: s.openid
                    },
                    success: function (t) {
                        var e;
                        if (1 == t.flag) {
                            that.setData((a((e = {}), 'LIST2[' + i + '][' + r + '].btn.class', 'ed'), a(e, 'LIST2[' + i + '][' + r + '].btn.title', '互相关注'), e));
                        } else {
                            uni.showToast({
                                title: t.msg,
                                icon: 'none',
                                mask: true
                            });
                        }
                    }
                });
            } else {
                uni.showModal({
                    content: '取消关注后，你将无法接收Ta的动态哦',
                    confirmColor: that.color,
                    cancelText: '我再想想',
                    confirmText: '取消关注',
                    success: function (t) {
                        if (t.confirm) {
                            app.globalData.ajax({
                                url: 'my_follow.php',
                                data: {
                                    submitok: 'ajax_fans_del',
                                    uid: o,
                                    openid: s.openid
                                },
                                success: function (t) {
                                    var e;
                                    1 == t.flag
                                        ? that.setData((a((e = {}), 'LIST2[' + i + '][' + r + '].btn.class', 'addgz'), a(e, 'LIST2[' + i + '][' + r + '].btn.title', '关注'), e))
                                        : uni.showToast({
                                              title: t.msg,
                                              icon: 'none',
                                              mask: true
                                          });
                                }
                            });
                        }
                    }
                });
            }
        },

        hmdFn: function (t) {
            var that = this;
            uni.showModal({
                content: '真的要取消拉黑？',
                confirmColor: that.color,
                cancelText: '我再想想',
                confirmText: '取消拉黑',
                success: function (o) {
                    if (o.confirm) {
                        var i = t.currentTarget.dataset.uid;
                        var r = t.currentTarget.dataset.idx_list;
                        var c = t.currentTarget.dataset.idx_dl;
                        app.globalData.ajax({
                            url: 'my_follow.php',
                            data: {
                                submitok: 'ajax_hmd',
                                uid: i,
                                openid: s.openid
                            },
                            success: function (t) {
                                1 == t.flag
                                    ? that.setData(a({}, 'LIST3[' + r + '][' + c + ']', null))
                                    : uni.showToast({
                                          title: t.msg,
                                          icon: 'none',
                                          mask: true
                                      });
                            }
                        });
                    }
                }
            });
        }
    }
};
</script>
<style>
@import 'follow.css';
</style>
